class functionTools {
  static getUrlParam (paramName) {
    let [paramValue, isFound] = ['', !1];
    let paramUrl = window.location.href.split('?')[1];
    if (paramUrl && paramUrl.indexOf('=') > 1) {
      const arrSource = paramUrl.split('&');
      let i = 0;
      while (i < arrSource.length && !isFound) {
        const item = arrSource[i];
        if (item.indexOf('=') > 0 && item.split('=')[0].toLowerCase() === paramName.toLowerCase()) {
          paramValue = item.split('=')[1];
          isFound = !0;
        }
        i++;
      }
    }
    paramValue === '' && (paramValue = null);
    return paramValue;
  }

  static getCookie (name) {
    const strcookie = document.cookie; // 获取cookie字符串
    const arrcookie = strcookie.split('; '); // 分割
    // 遍历匹配
    for (let i = 0; i < arrcookie.length; i++) {
      const arr = arrcookie[i].split('=');
      if (arr[0] === name) {
        return arr[1];
      }
    }
    return '';
  }

  static setSession (key, param) {
    window.sessionStorage.setItem(key, JSON.stringify(param));
  }

  static getSession (key) {
    if (window.sessionStorage.getItem(key)) {
      return JSON.parse(window.sessionStorage.getItem(key));
    } else {
      return !1;
    }
  }

  static add0 (m) {
    return m < 10 ? '0' + m : m;
  }

  static transferDate (nS) {
    var time = new Date(nS);
    var y = time.getFullYear();
    var m = time.getMonth() + 1;
    var d = time.getDate();
    var h = time.getHours();
    var mm = time.getMinutes();
    var s = time.getSeconds();
    return y + '-' + functionTools.add0(m) + '-' + functionTools.add0(d);
  }
}

export default functionTools;
